#!/bin/sh
#
# Genera la cápsula de PlanetaLibre.
#

# shellcheck disable=1091
[ -r /etc/profile ] && . /etc/profile

mkdir -p docs

(cd site && find . -type f -name \*.gemini) |
  while IFS= read -r file; do
    file=${file#./}

    (
      head -n -1 header.gemini
      cat "site/${file}"
      printf '\n'
      cat footer.gemini
    ) > "docs/${file}"
  done

planetalibre \
  --domain reisub.nsupdate.info/planetalibre \
  --output docs

ncftpput \
  -t 8 \
  -f "${HOME}/ncftp/planetalibre-login.cfg" \
  -R / docs/.
